﻿using AutoMapper;
using Medical.Api.Read.Application.Command.BasicManagement.DeviceDictionaryCommand;
using Medical.Api.Read.Application.Command.Wms.WmsStorageCommand;
using Medical.Api.Read.Dto.BasicManagement.DeviceDictionaryDto;
using Medical.Api.Read.Dto.WmsDto.WmsStorageDto;
using Medical.Api.Read.Dto.WmsDto.WmsStoresDro;
using Medical.Domain.Wms;
using System.ComponentModel;
using Medical.Domain.Enum;
using Medical.Domain.BasicManagement;
using System;

namespace Medical.Api.Read.AutoMapper
{
    public class WmsMapper : Profile
    {
        public WmsMapper()
        {
            // 设备查询DTO映射配置
            CreateMap<StorageQueryDto, QueryStorageCommand>()
                .ForMember(dest => dest.QueryDto, opt => opt.MapFrom(src => src));
            CreateMap<WmsStores, WmsStoresPageDto>()
                .ForMember(dest => dest.MaterialType, opt => opt.MapFrom(src => (int)src.MaterialType))
                .ForMember(dest => dest.MaterialTypeName, opt => opt.MapFrom(src => GetEnumDescription(src.MaterialType)))
                .ForMember(dest => dest.MaterialName, opt => opt.Ignore());
        }

        private static string GetEnumDescription(Enum value)
        {
            var field = value.GetType().GetField(value.ToString());
            var attr = (DescriptionAttribute)Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
            return attr != null ? attr.Description : value.ToString();
        }
    }
}
